import jwt
import datetime
from jwt import exceptions

SALT = 'iv%x6xo7l7_u9bf_u!9#g#m*)*=ej@bek5)(@u3kh*72+unjv='


def create_token():
    # 构造header
    headers = {
        'typ': 'jwt',
        'alg': 'HS256'
    }
    # 构造payload
    payload = {
        'user_id': 1,  # 自定义用户ID
        'username': 'wupeiqi',  # 自定义用户名
        'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=5)  # 超时时间
    }
    result = jwt.encode(payload=payload, key=SALT, algorithm="HS256", headers=headers)
    return result


if __name__ == '__main__':
    token = create_token()
    print(token)
# eyJ0eXAiOiJqd3QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6Ind1cGVpcWkiLCJleHAiOjE2NDc2MjMzMDR9.mC409LXIl1RZu4OX5J01hvCxWEOJcK7C4P3zKzedXdU
# test3
# 最后一试 修改npm镜像源aaaaaaabbbcccccddddddddd
#  最最最后一次啦 ！！！this is master